﻿#region << 版 本 注 释 >>

/*----------------------------------------------------------------
* 类 名 称 ：MonoBehaviourExtension
* 类 描 述 ：
* 作    者 ：henrychang
* 创建时间 ：2019/1/13 12:47:30
*******************************************************************
* Copyright @ henrychang 2019. All rights reserved.
*******************************************************************
//----------------------------------------------------------------*/

#endregion << 版 本 注 释 >>

using System;
using System.Collections;
using TouchFish.NodeActionSystem;
using UnityEngine;

namespace TouchFish.Extention
{
    public static class MonoBehaviourExtension
    {
        #region NodeActionSystem

        public static void ExecuteNode(this MonoBehaviour selfBehaviour, IAction commandNode)
        {
            selfBehaviour.StartCoroutine(commandNode.ExecuteExtension());
        }

        public static void Delay(this MonoBehaviour selfBehaviour, float seconds, Action delayEvent)
        {
            selfBehaviour.ExecuteNode(DelayAction.Allocate(seconds, delayEvent));
        }

        public static IEnumerator ExecuteExtension(this IAction selfNode)
        {
            if (selfNode.Finished) selfNode.Reset();

            while (!selfNode.Execute())
            {
                yield return null;
            }
        }

        #endregion NodeActionSystem
    }
}